package com.endbd.purchase.manage.product.control;

import com.endbd.feignapi.model.purchase.CProduct;
import com.endbd.feignapi.util.PageModel;
import com.endbd.feignapi.util.ResultMessage;
import com.endbd.purchase.manage.product.model.ProductCondition;
import com.endbd.purchase.manage.product.service.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/purchase")
@RestController
public class ProductAction {

    @Autowired
    private IProductService productService;

    @RequestMapping("/productPage")
    public ResultMessage ProductPage(PageModel<CProduct> pageModel, ProductCondition pcon){
        System.out.println("pcon"+pcon);
        PageModel<CProduct> productPageModel = productService.queryProductPageByCondition(pageModel,pcon);
        ResultMessage msg = new ResultMessage();
        msg.setStatus("200");
        msg.setFlag(true);
        msg.setMsg("查询成功！");
        msg.setResultData(productPageModel);

        return msg;
    }

    @RequestMapping("/addProduct")
    public ResultMessage addProduct(CProduct product,String brandName,String typeName,String firmName){
        productService.addProduct(product,brandName,typeName,firmName);

        ResultMessage msg = new ResultMessage();
        msg.setStatus("200");
        msg.setFlag(true);
        msg.setMsg("添加了"+product.getProductModel()+"商品");
        return msg;
    }

    @RequestMapping("/alterProduct")
    public ResultMessage alterProduct(CProduct product,String brandName,String typeName,String firmName){
        productService.alterProduct(product,brandName,typeName,firmName);
        ResultMessage msg = new ResultMessage();
        msg.setStatus("200");
        msg.setFlag(true);
        msg.setMsg("修改为"+product.getProductModel()+"商品");
        return msg;
    }

    @RequestMapping("/lorProduct")
    public ResultMessage lorProduct(ProductCondition pcon){
        productService.lor(pcon);

        ResultMessage msg = new ResultMessage();
        msg.setStatus("200");
        msg.setFlag(true);
        if (pcon.getProductStatus()==1){
            msg.setMsg("禁用了"+pcon.getProductModel()+"商品");
        }else {
            msg.setMsg("恢复了"+pcon.getProductModel()+"商品");
        }
        return msg;
    }
}
